<template>
    <div>
        <table class="table">
            <tbody>
                <tr>
                    <td>卡卷名称</td>
                    <td>
                        <input type="text" v-model="date.inStaeName">
                    </td>
                </tr>
                <tr>
                    <td>卡卷类型</td>
                    <td>
                        <select v-model="date.inStateId">
                            <option value="0">请选择</option>
                            <option v-for="b in data1" :value="b.inStateId">{{ b.inStateName }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>适用范围</td>
                    <td>
                        <select v-model="date.memberId">
                            <option value="0">请选择</option>
                            <option v-for="c in data3" :value="c.memberId">{{ c.memberName }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>适用日期</td>
                    <td>
                        <span v-for="b in hobby">
                            <input type="checkbox" v-model="hs" :value="b">{{ b }}
                        </span>
                    </td>
                </tr>
                <tr>
                    <td>有效期</td>
                    <td>
                        <input type="text" v-model="date.yong">
                    </td>
                </tr>
                <tr>
                    <td>价格</td>
                    <td>
                        <input type="text" v-model="date.price">
                    </td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td>
                        <select v-model="date.isTteId">
                            <option value="0">请选择</option>
                            <option v-for="h in data2" :value="h.isTteId">{{ h.isTteName }}</option>
                            
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>图片</td>
                    <td>
                        <input type="file" @change="upload">
                        <img :src="'https://localhost:7101/'+date.img" height="100px" width="100px">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td colspan="2">
                        <input type="button" value="修改" @click="update">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';
import { useRouter } from 'vue-router';
const routher = useRouter();

onMounted(()=>{

    getdatea()
    getdateb()
    getdatec()
})
const upload=(e:any)=>{
    var a = e.target.files[0]
    var aa = new FormData()
    aa.append("file",a)

    if(a.size>2*1024*1024){
        alert("上传文件的大小不能超过1MB")
        return
    }
    if(a.type!="image/jpeg"&&a.type!="image/png"){
        alert("格式只能为JPEG、PNG、GIF")
        return
    }
    axios.post("/api/UpLoad/UpFile",aa).then(res=>{
        date.value.img=res.data
        alert("上传成功")
    })
}

const hobby=ref(["周一","周二","周三","周四","周五","周六","周日"])
const hs=ref([])
const update=()=>{
    date.value.dateNum=hs.value.length
    date.value.dateName=hs.value.toString()
    axios.post("/api/InStae/AddInStae",date.value).then(res=>{
        if(res.data>0){
            alert("新增成功")
            routher.push({path:"/Show"})
        }
        else{
            alert("新增失败")
        }
    })
}
const date=ref({
    "memberId": 0,
    "inStaeId": 0,
    "isTteId": 0,
    "inStateId": 0,
    "dateName": "",
    "dateNum": 0,
    "inStaeName": "",
    "img": "",
    //"isDelete": false,
    "price": 0,
    "inStateName": "",
    "isTteName": "",
    "memberName": "",
    "yong":""
})
//卡卷
const getdatea=()=>{
    axios.get("/api/InState/GetInStates").then(res=>{
        data1.value=res.data
    })
}
const data1=ref([{
    "inStateId": 0,
    "inStateName": ""
}])
//状态
const getdateb=()=>{
    axios.get("/api/IsTae/GetIsTtes").then(res=>{
        data2.value=res.data
    })
}
const data2=ref([{
    "isTteId": 0,
    "isTteName": ""
}])
//门店
const getdatec=()=>{
    axios.get("/api/Member/GetMembers").then(res=>{
        data3.value=res.data
    })
}
const data3=ref([{
    "memberId": 0,
    "memberName": ""
}])
</script>

<style scoped>

</style>